package com.ruoyi.web.controller.admin;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PetCategory;
import com.ruoyi.system.service.IPetCategoryService;

/**
 * 宠物分类Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/category")
public class CategoryController extends BaseController
{
    @Autowired
    private IPetCategoryService petCategoryService;

    /**
     * 查询宠物分类列表
     */
//    @PreAuthorize("@ss.hasPermi('pet:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetCategory petCategory)
    {
        startPage();
        List<PetCategory> list = petCategoryService.selectPetCategoryList(petCategory);
        return getDataTable(list);
    }

    /**
     * 获取宠物分类详细信息
     */
//    @PreAuthorize("@ss.hasPermi('pet:category:query')")
    @GetMapping(value = "/get/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(petCategoryService.selectPetCategoryById(categoryId));
    }

    /**
     * 新增宠物分类
     */
//    @PreAuthorize("@ss.hasPermi('pet:category:add')")
    @Log(title = "宠物分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PetCategory petCategory)
    {
        return toAjax(petCategoryService.insertPetCategory(petCategory));
    }

    /**
     * 修改宠物分类
     */
//    @PreAuthorize("@ss.hasPermi('pet:category:edit')")
    @Log(title = "宠物分类", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody PetCategory petCategory)
    {
        return toAjax(petCategoryService.updatePetCategory(petCategory));
    }

    /**
     * 删除宠物分类
     */
//    @PreAuthorize("@ss.hasPermi('pet:category:remove')")
    @Log(title = "宠物分类", businessType = BusinessType.DELETE)
    @PostMapping("/del/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(petCategoryService.deletePetCategoryByIds(categoryIds));
    }
}
